package com.example.xd.mvp_project.view.fragment;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.xd.mvp_project.R;
import com.example.xd.mvp_project.adapter.MainHeadRecycleAdapter;
import com.example.xd.mvp_project.base.BaseFragment;
import com.example.xd.mvp_project.widget.pullextend.ExtendListHeader;
import com.youth.banner.Banner;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;

/**
 * A simple {@link Fragment} subclass.
 */
public class MainFg extends BaseFragment {


    private ExtendListHeader mMainFgElh;
    private RecyclerView mHeadRecyclerView;
    ArrayList<Integer> headList = new ArrayList<>();
    ArrayList<Integer> bannerImgs = new ArrayList<>();
    private MainHeadRecycleAdapter mMainHeadRecycleAdapter;
    private Banner mMainFgBanner;
    private RecyclerView mMainFgRecycle;


    public MainFg() {
    }

    @Override
    public View bindView(LayoutInflater inflater, ViewGroup container) {
        return inflater.inflate(R.layout.fragment_fg_main, container, false);
    }

    @Override
    protected void initView(View view, Bundle bundle, Bundle savedInstanceState) {
        mMainFgElh = view.findViewById(R.id.main_fg_elh);
        mMainFgBanner = view.findViewById(R.id.main_fg_banner);
        mMainFgRecycle = view.findViewById(R.id.main_fg_recycle);
        mHeadRecyclerView = mMainFgElh.getRecyclerView();

        mHeadRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity, LinearLayoutManager.HORIZONTAL, false));
        mMainHeadRecycleAdapter = new MainHeadRecycleAdapter(R.layout.main_head_recycle_item, headList, mActivity);
        mHeadRecyclerView.setAdapter(mMainHeadRecycleAdapter);



    }

    @Override
    protected void setListener() {

    }

    @Override
    protected void initData() {
        initHeadRecycle();
        initBanner();

    }

    private void initBanner() {
        bannerImgs.add(R.mipmap.img1);
        bannerImgs.add(R.mipmap.img2);
        bannerImgs.add(R.mipmap.img3);
        bannerImgs.add(R.mipmap.img4);
        bannerImgs.add(R.mipmap.img5);
        bannerImgs.add(R.mipmap.img6);
        bannerImgs.add(R.mipmap.img7);
        bannerImgs.add(R.mipmap.img8);
        bannerImgs.add(R.mipmap.img9);

        mMainFgBanner.setImages(bannerImgs);
        mMainFgBanner.setImageLoader(new ImageLoader() {
            @Override
            public void displayImage(Context context, Object path, ImageView imageView) {
                Glide.with(context).load(path).centerCrop().into(imageView);
            }
        });
        mMainFgBanner.start();
    }

    private void initHeadRecycle() {
        headList.add(R.mipmap.yoo);
        headList.add(R.mipmap.yoo);
        headList.add(R.mipmap.yoo);
        headList.add(R.mipmap.yoo);
        headList.add(R.mipmap.yoo);
        headList.add(R.mipmap.yoo);
        headList.add(R.mipmap.yoo);

        mMainHeadRecycleAdapter.notifyDataSetChanged();
    }

    @Override
    protected void widgetClick(View v) {

    }
}
